﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using SPIWareMVVM.ViewModels;
using DataAccess;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Data;

namespace SPIWareMVVM.Views.Commands
{
    public class ShowWODeliveriesListCommand : BaseCommand
    {
        ApplicationViewModel _sender { get; set; }
        ApplicationViewModel applicationViewModel { get; set; }

        public ShowWODeliveriesListCommand(BaseViewModel sender) : base(sender){ }

        public override void Execute(object parameter)
        {
            DeliveryList list = null;
            if (parameter != null) list = (DeliveryList)parameter;

            if (list != null)
            {
                if (mainWindow == null) mainWindow = (Window1)Window.GetWindow((DeliveryList)list);

                if (mainWindow != null)
                    applicationViewModel = (ApplicationViewModel)((ObjectDataProvider)mainWindow.Resources["applicationVM"]).ObjectInstance;
                if (applicationViewModel != null)
                {
                    applicationViewModel.SelectedCustomer = null;
                    ApplicationData.ClearAllExcept(new List<Type> { typeof(WorkOrder) });
                    mainWindow.HideLists();

                    list.lbDelivery.ItemsSource = null;
                    //list.lbDelivery.ItemsSource = ApplicationData.SelectedWorkOrder.del
                    list.lbDelivery.SelectedIndex = -1;

                    mainWindow.workOrdersList.Visibility = Visibility.Visible;
                    mainWindow.deliveryList.Visibility = Visibility.Visible;
                }
            }
        }
    }
}
